<template>
    <div id="fireManagement">
        <div style="height: 100%;">
            <div class="trees">
                <div class="tree_title">
                    <h3 class="tree_title_h3">机构列表</h3>
                </div>
                <div class="tree_body">
                    <Tree :data="baseData" @on-select-change="clickTree"></Tree>
                </div>
            </div>
            <div class="body_right">
                <div class="header-right">
                    消防人员管理
                    <!--<Button type="ghost" icon="ios-plus-empty" size="small" style="float:right;" @click="editForStaffClick">部门角色授权</Button>-->
                    <Modal v-model="editForStaffModel" title="角色授权" :closable="false" :mask-closable="false" width="500">
                        <div class="compile">
                            <Table stripe border :columns="columns" :data="tabledata" @on-selection-change="editForStaffSelect"></Table>
                        </div>
                        <div class="page_container">
                            <Page :current="pageNo" :total="editForStaffTotalCount" size="small" simple class="page_btn"
                                  @on-change="pageChange"></Page>
                            <P class="page_text">共{{editForStaffTotalCount}}条</P>
                        </div>
                        <div slot="footer">
                            <Button type="ghost" size="small" @click="editForStaffCancel">取消</Button>
                            <Button type="primary" size="small" @click="editForStaffConfirm">确定</Button>
                        </div>
                    </Modal>
                </div>
                <div class="btn_group">
                    <Input v-model="materials_name" placeholder="姓名" style="width: 15rem;" size="small"></Input>
                    <Button type="primary" icon="ios-search" size="small" @click="search">查询</Button>
                    <Button type="ghost" icon="ios-download-outline" size="small" style="float:right;margin-right: 6px" @click="channel">人员导入</Button>
                    <Button type="ghost" icon="ios-trash-outline" size="small" style="float:right;margin-right: 6px" @click="batchDele">批量删除</Button>
                    <Button type="ghost" icon="ios-plus-empty" size="small" style="float:right;margin-right: 6px" @click="add">新增</Button>
                </div>
                <div class="tableWidth">
                    <Table border :columns="columns7" :data="data6" stripe  @on-selection-change="compileSelect"></Table>
                </div>
                <!--消防人员管理表-->
                <Modal v-model="modal5" title="消防人员信息" width="800" id="modal" :closable="false" :mask-closable="false">
                    <Form action="post" ref="formValidate" :model="formValidate" :rules="ruleValidate"
                          :label-width="110" style="margin-right: 20px">
                        <Form-item label="所属单位" prop="departmentName">
                            <p>{{formValidate.departmentName}}</p>
                        </Form-item>
                        <Row>
                            <Col span="8">
                            <Form-item label="姓名" prop="name">
                                <Input v-model="formValidate.name" placeholder="姓名"></Input>
                            </Form-item>
                            </Col>
                            <Col span="8">
                            <Form-item label="性别" prop="genderName">
                                <Radio-group v-model="formValidate.genderName">
                                    <Radio label="1">男</Radio>
                                    <Radio label="0">女</Radio>
                                </Radio-group>
                            </Form-item>
                            </Col>
                            <Col span="8">
                            <Form-item label="民族" prop="nation">
                                <Input v-model="formValidate.nation" placeholder="民族"></Input>
                            </Form-item>
                            </Col>
                        </Row>
                        <Row>
                            <Col span="8">
                            <Form-item label="出生年月" prop="birthday">
                                <Date-picker type="date" placeholder="选择日期" v-model="formValidate.birthday"
                                             @on-change="showBirthday"></Date-picker>
                            </Form-item>
                            </Col>
                            <Col span="8">
                            <Form-item label="政治面貌" prop="politicalOutlook">
                                <Input v-model="formValidate.politicalOutlook" placeholder="政治面貌"></Input>
                            </Form-item>
                            </Col>
                            <Col span="8">
                            <Form-item label="籍贯" prop="nativePlace">
                                <Input v-model="formValidate.nativePlace" placeholder="籍贯"></Input>
                            </Form-item>
                            </Col>
                        </Row>
                        <Row>
                            <Col span="8">
                            <Form-item label="身份证号码" prop="identityNumber">
                                <Input v-model="formValidate.identityNumber" placeholder="身份证号码"></Input>
                            </Form-item>
                            </Col>
                            <Col span="8">
                            <Form-item label="身高(cm)" prop="stature">
                                <Input-number v-model="formValidate.stature" placeholder="身高" :min="0" style="width: 140px;"></Input-number>
                            </Form-item>
                            </Col>
                            <Col span="8">
                            <Form-item label="体重(kg)" prop="weight">
                                <Input-number v-model="formValidate.weight" placeholder="体重" :min="0" style="width: 140px;"></Input-number>
                            </Form-item>
                            </Col>
                        </Row>
                        <Row>
                            <Col span="8">
                            <Form-item label="婚姻状况" prop="isMarriedName">
                                <Select v-model="formValidate.isMarriedName" clearable  placeholder="婚姻状况">
                                    <Option value="0">已婚</Option>
                                    <Option value="1">未婚</Option>
                                </Select>
                            </Form-item>
                            </Col>
                            <Col span="8">
                            <Form-item label="学历" prop="education">
                                <Input v-model="formValidate.education" placeholder="最高学历"></Input>
                            </Form-item>
                            </Col>
                            <Col span="8">
                            <Form-item label="在职状态" prop="isIncumbencyName">
                                <Select v-model="formValidate.isIncumbencyName" clearable  placeholder="在职状态">
                                    <Option value="1">在职</Option>
                                    <Option value="0">离职</Option>
                                </Select>
                            </Form-item>
                            </Col>
                        </Row>
                        <Row>
                            <Col span="8">
                            <Form-item label="职务" prop="businessName">
                                <Select clearable v-model="formValidate.businessName" clearable  placeholder="职务">
                                    <Option v-for="item in businessData" :value="item.value" :key="item.value">
                                        {{item.value}}
                                    </Option>
                                </Select>
                            </Form-item>
                            </Col>
                            <Col span="8">
                            <Form-item label="联系电话" prop="phone">
                                <Input v-model="formValidate.phone" placeholder="联系电话"></Input>
                            </Form-item>
                            </Col>
                            <Col span="8">
                            <Form-item label="参加工作时间" prop="attendworkTime">
                                <Date-picker type="date" placeholder="选择日期" v-model="formValidate.attendworkTime"
                                             @on-change="showAttend"></Date-picker>
                            </Form-item>
                            </Col>
                        </Row>
                        <Row>
                            <Col span="8">
                            <Form-item label="人员编号" prop="staffCode">
                                <Input v-model="formValidate.staffCode" placeholder="人员编号" ></Input>
                            </Form-item>
                            </Col>
                            <Col span="8">
                            <Form-item label="入职时间" prop="hiredate">
                                <Date-picker type="date" placeholder="选择日期" v-model="formValidate.hiredate"
                                             @on-change="showHiredate"></Date-picker>
                            </Form-item>
                            </Col>
                        </Row>
                        <Form-item label="家庭情况" prop="familySituation">
                            <Input v-model="formValidate.familySituation" type="textarea" :autosize="true" :maxlength="maxlen"
                                   placeholder="请输入...(200字以内)"></Input>
                        </Form-item>
                        <Form-item label="个人简介" prop="resume">
                            <Input v-model="formValidate.resume" type="textarea" :autosize="true" :maxlength="maxlen"
                                   placeholder="请输入...(200字以内)"></Input>
                        </Form-item>
                        <Form-item label="专长爱好" prop="speciality">
                            <Input v-model="formValidate.speciality" type="textarea" :autosize="true" :maxlength="maxlen"
                                   placeholder="请输入...(200字以内)"></Input>
                        </Form-item>
                        <Form-item label="其他情况" prop="elseSituation">
                            <Input v-model="formValidate.elseSituation" type="textarea" :autosize="true" :maxlength="maxlen"
                                   placeholder="请输入...(200字以内)"></Input>
                        </Form-item>
                    </Form>
                    <div slot="footer">
                        <Button type="ghost" size="small" @click="cancelFrom">取消</Button>
                        <Button type="primary" size="small" @click="handleSubmit('formValidate')">提交</Button>
                    </div>
                </Modal>
                <!-- 分页显示-->
                <div class="page_container">
                    <Page :current="currentPage" :total="totalCount" size="small" simple class="page_btn"
                          @on-change="changePage"></Page>
                    <P class="page_text">共{{totalCount}}条</P>
                </div>
                <Modal v-model="personnelImport" title="人员导入" :closable="false" :mask-closable="false" width="500">
                    <div style="margin-left:50px ">
                        <Steps :current="stepsNumber" size="small">
                            <Step title="选择文件"></Step>
                            <Step title="解析中"></Step>
                            <Step title="导入完成"></Step>
                        </Steps>
                    </div>
                    <div style="height:135px;padding: 20px;border-top: 1px solid #ddd;">
                        <div v-if="uploadShow1">
                            <Upload :action="$nfs.uploadUrl"  accept=".xls" :format="['xls']"  ref="uploadFile" :on-progress="disableConfirm" :on-error="handleError" :on-success="handleSuccess">
                                <Button type="ghost" icon="ios-cloud-upload-outline">上传文件</Button>
                            </Upload>
                            <h3>导入说明：</h3>
                            <p>请使用Excel等软件编辑模板文件，点击<a href="/xls/员工导入模板.xls" style="color: #39f;" target="_blank">下载模板</a>：</p>
                        </div>
                        <div v-if="uploadShow2">
                            <Row>
                                <Col class="demo-spin-col" span="24">
                                <Spin fix>
                                    <Icon type="load-c" size=18 class="demo-spin-icon-load"></Icon>
                                    <div>解析中</div>
                                </Spin>
                                </Col>
                            </Row>
                        </div>
                        <div v-if="uploadShow3">
                            <h3 style="text-align: center">文件导入完成，{{uploadFailure}}条记录导入失败。</h3>
                            <ul style="height: 105px;overflow: auto">
                                <li v-for="list in uploadFailureList">{{list}}</li>
                            </ul>
                        </div>
                    </div>
                    <div slot="footer">
                        <Button type="ghost" size="small" @click="personnelImportCancel" v-if="uploadShow3">关闭</Button>
                        <Button type="ghost" size="small" @click="personnelImportCancel" v-if="uploadShow1">取消</Button>
                        <Button type="primary" size="small" :loading="modal_loading" @click="personnelImportUp" v-if="uploadShow1">提交</Button>
                    </div>
                </Modal>
            </div>
        </div>
    </div>
</template>
<script type="text/javascript">
    var ezjsUtil = Vue.ezjsUtil;
    var apiConstants = ezjsUtil.constants.api;
    export default {
        data() {
          const validateTimes = (rule, value, callback) => {
            if (value === '' || value == null) {
              callback(new Error('请选择日期'));
            }else {
              callback();
            }
          };
            const staffCodeChange = (rule, value, callback) => {
                if (value.replace(/(^\s*)|(\s*$)/g, "") == '') {
                    callback(new Error('人员编号不能为空'));
                }else{
                    var _this = this;
                    ezjsUtil.request(apiConstants.staffManagement_checkStaffCodeExist,
                        {
                            id: _this.formValidate.id,
                            staffCode: value
                        },
                        function (err, data) {
                            if (err) {
                                return;
                            }
                            if(data==1){
                                callback();
                            }else {
                                callback(new Error('人员编号已存在'));
                            }
                        }
                    )
                }
            };
            return {
              departmentCode:CURRENT_LEADER.departmentCode,  //登录人员code值
              valueLen:'', //点击树获得的code值
                maxlen:200,
                modal_loading:false,
                stepsNumber:0,
                personnelImport:false,//人员导入
                uploadShow1:true,
                uploadShow2:false,
                uploadShow3:false,
                uploadFailure:0,
                uploadFailureList:[],
                importFromExcelFilePath:'',//文件地址
                editForStaffModel: false,//角色授权
                editForStaffPersonnelId:'',
                pageNo:1,
                editForStaffTotalCount:null,
                editForStaff:{
                    staffId:'',
                    departmentCode:'',
                    personnelId:'',
                },
                roleAccreditId:'',
                materials_name: '', //按照物资名称搜索
                search_code: '', //按照物资名称搜索
                idss: "",   //批量删除项（各项ids值-以字符串形式串联起来，逗号分割）
                currentPage: 1, //当前页
                totalCount: 0,  //总条数
                baseData: [],
                businessData: [],
                roleData: [],
                //表格头部信息
                columns: [
                    {
                        type: 'selection',
                        width: 60,
                        align: 'center'
                    },
                    {
                        type: 'index',
                        width: 60,
                        align: 'center'
                    },
                    {
                        title: '角色名称',
                        key: 'name',
                        align: 'center'
                    },
                ],
                //表格数据
                tabledata: [],
                /*  表头开始*/
                columns7: [
                    {
                        type: 'selection',
                        width: 60,
                        align: 'center'
                    },
                    {
                        title: '所属单位',
                        key: 'departmentName',
                        align: 'center'
                    },
                    {
                        title: '姓名',
                        key: 'name',
                        align: 'center'

                    },
                    {
                        title: '人员编号',
                        key: 'staffCode',
                        align: 'center'

                    },
                    {
                        title: '性别',
                        key: 'genderName',
                        align: 'center',
                        render: (h, params) => {
                            const row = params.row;
                            const text = row.genderName == 1 ? '男' : '女';
                            return h('div', {
                                props: {}
                            }, text);
                        }
                    },
                    {
                        title: '职务',
                        key: 'businessName',
                        align: 'center'

                    },
                    {
                        title: '状态',
                        key: 'isIncumbencyName',
                        align: 'center',
                        render: (h, params) => {
                            const row = params.row;
                            const text = row.isIncumbencyName == 1 ? '在职' : '离职';
                            return h('div', {
                                props: {}
                            }, text);
                        }

                    },
                    {
                        title: '入职时间',
                        key: 'hiredate',
                        align: 'center',
  /*                      render: function (h, params) {
                            var newTime = new Date(params.row.hiredate);
                            var Y = newTime.getFullYear();
                            var M = newTime.getMonth() + 1;
                            var D = newTime.getDate();
                            var H = newTime.getHours();
                            var m = newTime.getMinutes();
                            var s = newTime.getSeconds();
                            var time = Y + "-" + M + "-" + D;
                            return h('div', time);
                        }*/
                    },
                    {
                        title: '操作',
                        key: 'action',
                        align: 'center',
                        width: 280,
                        render: (h, params) => {
                            return h('div', [
                                h('Button', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'
                                    },
                                    style: {
                                        marginRight: '5px'
                                    },
                                    on: {
                                        click: () => {
                                            this.editForStaff.departmentCode ='';
                                            this.editForStaffModel=true;
                                            this.editForStaff.staffId=params.row.id;
//                                            this.authorityFlipListForPersonnel();
                                            this.authorityDetailForStaff(params.row.id);
                                        }
                                    }
                                }, '角色授权'),
                                h('Button', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'
                                    },
                                    style: {
                                        marginRight: '5px'
                                    },
                                    on: {
                                        click: () => {
                                            this.authorityResetPassword(params.row.id);
                                        }
                                    }
                                }, '重置密码'),
                                h('Button', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'
                                    },
                                    style: {
                                        marginRight: '5px'
                                    },
                                    on: {
                                        click: () => {
                                            this.carInfoEdit(params.row)
                                        }
                                    }
                                }, '修改'),
                                h('Button', {
                                    props: {
                                        type: 'error',
                                        size: 'small'
                                    },
                                    on: {
                                        click: () => {
                                            this.carRemoveInfo(params.row.id)
                                        }
                                    }
                                }, '删除')
                            ]);
                        }
                    },
                ],
                /*表头结束*/
                /* 表格数据显示区域*/
                data6: [],
                /* 全局变量*/
                modal5: false,
                formValidate: { //表单验证
                    id: '',
                    departmentName: '',                   //1    所属单位
                    departmentNameCopy: '',                   //1    所属单位
                    departmentCode: '',                   //1    所属单位
                    name: '',                              //2    物资名称
                    birthday: '',                          //3    出生年月
                    identityNumber: '',                    //4    身份证号码
                    stature:0,                              //5    身高
                    education: '',                          //6    学历
                    phone: '',                               //7    联系方式
                    staffCode: '',                          //8    人员编号
                    genderName: '1',                         //9    性别
                    politicalOutlook: '',                  //10    政治面貌
                    weight:0,                               //11    体重
                    isIncumbencyName: '1',                  //12    在职状态
                    attendworkTime: '',                    //13    参加工作时间
                    roleName: '',                           //14    角色名称
                    nation: '',                             //15    名族
                    nativePlace: '',                        //16    籍贯
                    isMarriedName: '',                      //17    婚姻状况
                    businessName: '',                       //18    职务名称
                    hiredate: '',                            //19    入职时间
                    address: '',                             //20    地址
                    familySituation: '',                    //21    家庭情况
                    resume: '',                              //22    个人简历
                    elseSituation: '',                       //23    其他情况
                    speciality: '',                          //24    特长
                },
                ruleValidate: {
                    name: [
                        {required: true, message: '姓名不能为空', trigger: 'blur'}
                    ],
                    departmentName: [
                        {required: true, message: '所属单位不能为空', trigger: 'blur'}
                    ],
                    staffCode: [
                        {required: true, validator: staffCodeChange, trigger: 'blur'}
                    ],
                    genderName: [
                        {required: true, message: '性别不能为空', trigger: 'change'},
                    ],
                    businessName: [
                        {required: true, message: '职务不能为空', trigger: 'change'}
                    ],
                    isIncumbencyName: [
                        {required: true, message: '状态不能为空', trigger: 'change'}
                    ],
                    hiredate: [
                        {required: true, validator: validateTimes, trigger: 'change'}
                    ],
                    birthday: [
                        {required: true, validator: validateTimes, trigger: 'change'}
                    ],
                    attendworkTime: [
                        {required: true, validator: validateTimes, trigger: 'change'}
                    ],
                    familySituation: [
                       {type:'string',max:200, message: '输入200字以内', trigger: 'change'}
                    ],
                    resume: [
                      {type:'string',max:200, message: '输入200字以内', trigger: 'change'}
                    ],
                    speciality: [
                      {type:'string',max:200, message: '输入200字以内', trigger: 'change'}
                    ],
                    elseSituation: [
                      {type:'string',max:200, message: '输入200字以内', trigger: 'change'}
                    ],
                     stature: [
                       {required: true,type:'number', message: '身高不能为空', trigger: 'change'}
                    ],
                    weight: [
                      {type:'number',required:true, message: '体重不能为空', trigger: 'change'}
                    ],
                }
            }
        },
        /* 在实例初始化之后，数据观测(data observer) 和 event/watcher 事件配置之前被调用。*/
        created() {
//            this.authorityFlipListForPersonnel();
            this.dictionary_flipList_role();
            this.dictionary_flipList();
            this.staffManagementFlipList();
            this.organization_flipList();
        },
        /*在挂载开始之前被调用：相关的 render 函数首次被调用。*/
        mounted: function () {

        },
        methods: {
            /*  改变值时获得当前值*/
            showHiredate(data) {
                this.formValidate.hiredate = data;

            },
            showBirthday(data) {
                this.formValidate.birthday = data;

            },
            showAttend(data) {
                this.formValidate.attendworkTime = data;

            },
            //部门授权
            editForStaffClick(){
                this.editForStaffPersonnelId='';
                if (this.formValidate.departmentName != '') {
                    this.formValidate.id = "";
                    this.authorityFlipListForPersonnel();
                    this.editForStaffModel=true;
                } else {
                    this.$Modal.info({
                        content: '请在机构列表选择机构单位！'
                    });
                };
            },
            //人员导入按钮
            channel(){
                this.personnelImport=true;
            },
            //上传过程中
            disableConfirm() {
                this.modal_loading = true;
            },
            //上传失败
            handleError() {
                this.$Message.error('上传失败!');
                this.modal_loading = false;
            },
            //上传成功
            handleSuccess(response, file, fileList){
                var _this = this;
                this.modal_loading = false;
                //删除之前传的内容
                if(_this.$refs.uploadFile.fileList.length > 1) {
                    _this.$refs.uploadFile.fileList.splice(0, 1);
            }
                _this.importFromExcelFilePath = ezjsUtil.nfsUtil.getFileUrl(response.data.token);
            },
            //解析Excel
            personnelImportUp(){
                var _this = this;
                if(_this.importFromExcelFilePath){
                    _this.stepsNumber=1;
                    _this.uploadShow1=false;
                    _this.uploadShow2=true;
                    ezjsUtil.request(apiConstants.staffManagement_importFromExcel,
                        {
                            filePath:_this.importFromExcelFilePath
                        },
                        function (err, data) {
                            if (err) {
                                return;
                            }
                            _this.uploadFailureList=data;
                            _this.uploadFailure=data.length;
                            _this.stepsNumber=2;
                            _this.uploadShow2=false;
                            _this.uploadShow3=true;
                            _this.staffManagementFlipList();
                        }
                    )
                }else {
                    this.$Modal.info({
                        content: '请选择需要导入的文档'
                    });
                }
            },
            personnelImportCancel(){
                this.personnelImport=false;
                this.stepsNumber=0;
                this.uploadShow1=true;
                this.uploadShow2=false;
                this.uploadShow3=false;
                this.importFromExcelFilePath='';
            },
            //角色授权确定
            editForStaffConfirm(){
                if(this.roleAccreditId.length !=1 ){
                    this.$Modal.info({
                        content: '请选择一个角色授权！'
                    });
                }else if(this.editForStaff.departmentCode !=''){
                    //为部门授权角色
                    this.editForStaff.personnelId=this.roleAccreditId[0].id;
                    var _this = this;
                    ezjsUtil.request(apiConstants.authority_editForDepartment,
                        {
                            departmentCode: _this.editForStaff.departmentCode,
                            personnelId: _this.editForStaff.personnelId,
                        },
                        function (err, data) {
                            if (err) {
                                return;
                            }
                            _this.editForStaffModel=false;
                            _this.tabledata=[];
                        }
                    )
                }else {
                    //为人员授权角色
                    this.editForStaff.personnelId=this.roleAccreditId[0].id;
                    var _this = this;
                    ezjsUtil.request(apiConstants.authority_editForStaff,
                        {
                            staffId: _this.editForStaff.staffId,
                            personnelId: _this.editForStaff.personnelId,
                        },
                        function (err, data) {
                            if (err) {
                                return;
                            }
                            _this.editForStaffModel=false;
                            _this.tabledata=[];
                        }
                    )
                }
            },
            editForStaffCancel(){
                this.editForStaffModel=false;
                this.tabledata=[];
            },
            editForStaffSelect(selection){
                this.roleAccreditId=selection;
            },
          add() {
            if (this.formValidate.departmentName != '') {
              this.formValidate.id = "";
              this.modal5 = true;
            }else if( this.valueLen <= 0){
              this.$Modal.info({
                content: '请在机构列表选择机构单位！'
              });
            }else{
              this.$Message.error('权限不够，无法新增，请联系管理员！');
            }
          },
            //日期格式转换
            dateformatting(dateval) {
                var newTime = new Date(dateval);
                var yyyy = newTime.getFullYear();
                var MM = newTime.getMonth() + 1;
                var dd = newTime.getDate();
                var hh = newTime.getHours();
                var mm = newTime.getMinutes();
                var ss = newTime.getSeconds();
                var time = yyyy + "-" + MM + "-" + dd + " " + hh + ":" + mm + ":" + ss;
                return time
            },
            carInfoEdit(value) { //修改
                console.log(value);
                this.formValidate.id = value.id;
                this.formValidate.departmentName = value.departmentName;
                this.formValidate.departmentCode = value.departmentCode;
                this.formValidate.name = value.name;
                this.formValidate.birthday = value.birthday;
                this.formValidate.identityNumber = value.identityNumber;
                this.formValidate.stature = value.stature;
                this.formValidate.education = value.education;
                this.formValidate.phone = value.phone;
                this.formValidate.staffCode = value.staffCode;
                this.formValidate.genderName = value.genderName;
                this.formValidate.politicalOutlook = value.politicalOutlook;
                this.formValidate.weight = value.weight;
                this.formValidate.isIncumbencyName = value.isIncumbencyName;
                this.formValidate.attendworkTime = value.attendworkTime;
                this.formValidate.roleName = value.roleName;
                this.formValidate.nation = value.nation;
                this.formValidate.nativePlace = value.nativePlace;
                this.formValidate.isMarriedName = value.isMarriedName;
                this.formValidate.businessName = value.businessName;
                this.formValidate.hiredate = value.hiredate;
                this.formValidate.address = value.address;
                this.formValidate.familySituation = value.familySituation;
                this.formValidate.resume = value.resume;
                this.formValidate.elseSituation = value.elseSituation;
                this.formValidate.speciality = value.speciality;
                this.modal5 = true;
            },
            cancelFrom() {  //单击取消重置并关闭模态框
                this.handleReset('formValidate');
                this.formValidate.departmentCode =this.search_code;
                this.formValidate.departmentName=this.formValidate.departmentNameCopy;
                this.modal5 = false;
            },
            pageChange(page) {     //分页展示
                this.pageNo = page;
                this.authorityFlipListForPersonnel();
            },
            changePage(page) {     //分页展示
                this.currentPage = page;
                this.staffManagementFlipList();
            },
            staffManagementFlipList() { //显示与查询接口
                var _this = this;
                ezjsUtil.request(apiConstants.staffManagement_flipList,
                    {
                        name: _this.materials_name,
                        pageNo: _this.currentPage,
                        departmentCode: _this.formValidate.departmentCode,
                    },
                    function (err, data) {
                        if (err) {
                            return;
                        }
                        _this.data6 = data.listInfo;
                        _this.totalCount = data.flipInfo.totalCount;
                    }
                )
            },
            staffManagement_edit() { //新增
                var _this = this;
                ezjsUtil.request(apiConstants.staffManagement_edit,
                    {
                        id: _this.formValidate.id,
                        departmentName: _this.formValidate.departmentName,
                        departmentCode: _this.formValidate.departmentCode,
                        name: _this.formValidate.name,
                        birthday: _this.formValidate.birthday,
                        identityNumber: _this.formValidate.identityNumber,
                        stature: _this.formValidate.stature,
                        education: _this.formValidate.education,
                        phone: _this.formValidate.phone,
                        staffCode: _this.formValidate.staffCode,
                        genderName: _this.formValidate.genderName,
                        politicalOutlook: _this.formValidate.politicalOutlook,
                        weight: _this.formValidate.weight,
                        isIncumbencyName: _this.formValidate.isIncumbencyName,
                        attendworkTime: _this.formValidate.attendworkTime,
                        roleName: _this.formValidate.roleName,
                        nation: _this.formValidate.nation,
                        nativePlace: _this.formValidate.nativePlace,
                        isMarriedName: _this.formValidate.isMarriedName,
                        businessName: _this.formValidate.businessName,
                        hiredate: _this.formValidate.hiredate,
                        address: _this.formValidate.address,
                        familySituation: _this.formValidate.familySituation,
                        resume: _this.formValidate.resume,
                        elseSituation: _this.formValidate.elseSituation,
                        speciality: _this.formValidate.speciality,
                    },
                    function (err, data) {
                        if (err) {
                            return;
                        }
                        _this.formValidate.departmentName="";
                        _this.formValidate.departmentCode="";
                        _this.valueLen='';
                        _this.staffManagementFlipList();
                        _this.organization_flipList();
                    }
                )
            },
            /* 删除数据部分starting*/
            compileSelect(selection, row) {   //表格选择
                var ids = [];
                for (var i = 0; i < selection.length; i++) {
                    ids.push(selection[i].id);
                }
                this.idss = ids.join(',');
            },
            carRemoveInfo(value) {  //单个删除
                this.idss = value;
                this.staffManagement_removeByIds();
            },
            batchDele() { //批量删除
              if(this.idss !==""){
                this.staffManagement_removeByIds(); //调用删除接口
              } else{
                  this.$Message.error('请选择删除项!');
              }

            },
            staffManagement_removeByIds() { //删除
                var _this = this;
                ezjsUtil.request(apiConstants.staffManagement_removeByIds,
                    {

                        ids: _this.idss   //将选中项的的ids给ids（字符串形式，逗号分隔）
                    },
                    function (err, data) {
                        if (err) {
                            return;
                        }
                        _this.idss='';
                        _this.staffManagementFlipList();
                    },
                )
            },
            search() { //查询
                this.currentPage=1;
                this.staffManagementFlipList();  //调用显示接口
            },
            handleSubmit(name) {  //表单验证
                this.$refs[name].validate((valid) => {
                    if (valid) {
                        this.staffManagement_edit();  //调用编辑接口
                        this.$Message.success('提交成功!');
                        this.modal5 = false;               //关闭模态框
                        this.handleReset(name);
                    } else {
                        this.$Message.error('表单验证失败!');
                    }
                })
            },
            handleReset(name) {  //重置
                this.$refs[name].resetFields();
            },
            /*组织机构数*/
            organization_flipList() { //显示 查询
                var _this = this;
                ezjsUtil.request(apiConstants.organization_flipList,
                    {},
                    function (err, data) {
                        if (err) {
                            return;
                        }
                        _this.baseData = data;
                        _this.baseData[0].expand=true;
                    }
                )
            },
          clickTree(value) {
            this.valueLen = value.length;
            if (this.valueLen > 0 && this.departmentCode<=value[0].code) {
              this.formValidate.departmentCode = value[0].code;
              this.formValidate.departmentName = value[0].fullTitle;
              this.formValidate.departmentNameCopy = value[0].fullTitle;
              this.search_code=value[0].code; this.search_code=value[0].code;
            }else {
              this.formValidate.departmentCode = '';
              this.formValidate.departmentName = '';
              this.formValidate.departmentNameCopy = '';
              this.search_code = '';
            }
            this.search();
          },
            /*字典数据相关接口*/
            dictionary_flipList() { //显示 查询
                var _this = this;
                ezjsUtil.request(apiConstants.dictionary_flipList,
                    {
                        key: "business",
                    },
                    function (err, data) {
                        if (err) {
                            return;
                        }
                        _this.businessData = data;
                    }
                )
            },
            dictionary_flipList_role() { //显示 查询
                var _this = this;
                ezjsUtil.request(apiConstants.dictionary_flipList,
                    {
                        key: "role",
                    },
                    function (err, data) {
                        if (err) {
                            return;
                        }
                        _this.roleData = data;
                    }
                )
            },
            //查询角色列表
            authorityFlipListForPersonnel(){
                var _this = this;
                ezjsUtil.request(apiConstants.authority_flipListForPersonnel,
                    {
                        pageNo: _this.pageNo
                    },
                    function (err, data) {
                        if (err) {
                            return;
                        }
                        for(var i=0;i<data.listInfo.length;i++){
                            if(data.listInfo[i].id==_this.editForStaffPersonnelId){
                                data.listInfo[i]._checked=true;
                                _this.roleAccreditId=[data.listInfo[i]];
                                break;
                            }
                        }
                        _this.tabledata=data.listInfo;
                        _this.editForStaffTotalCount=data.flipInfo.totalCount;
//                        _this.totalPage=data.flipInfo.totalPage;
                    }
                )
            },
            //查询人员角色
            authorityDetailForStaff(val){
                var _this = this;
                ezjsUtil.request(apiConstants.authority_detailForStaff,
                    {
                        id: val
                    },
                    function (err, data) {
                        if (err) {
                            return;
                        }
                        _this.editForStaffPersonnelId=data[0].personnelId;
                        _this.authorityFlipListForPersonnel();
                    }
                )
            },
            //重置密码
            authorityResetPassword(val){
                var _this = this;
                ezjsUtil.request(apiConstants.authority_resetPassword,
                    {
                        id: val
                    },
                    function (err, data) {
                        if (err) {
                            return;
                        }
                        if(data==1){
                            _this.$Message.success('重置密码成功');
                        }else {
                            _this.$Message.error('重置密码失败');
                        }
                    }
                )
            },
        }
    }
</script>
<style lang="less" scoped>
    #fireManagement {
        height: 100%;
        overflow: auto;
        padding: 15px;

    .trees {
        width: 260px;
        height: 100%;
        padding-bottom: 30px;
        float: left;
        border: 1px solid #d3d8e0;
        overflow: auto;

    .tree_title {
        height: 40px;
        border-bottom: 1px solid #d3d8e0;

    .tree_title_h3 {
        line-height: 40px;
        text-align: center;
        font-size: 14px;
        color: #6e6d6d;
    }

    }
    .tree_body {
        padding: 10px;
    }

    }
    .body_right {
        margin-left: 280px;
        height: 100%;
        overflow: auto;

    .header-right {
        height: 40px;
        border-bottom: 1px solid #d3d8e0;
        font-size: 14px;
        color: #657180;
        line-height: 40px;
        font-family: '微软雅黑';
    }

    .btn_group {
        width: 100%;
        padding: 1.5rem 0;
    }

    .tableWidth {
        width: 100%;
    }

    }

    }
    .page_container {
        height: 30px;
        margin-top: 20px;

    .page_btn {
        float: right;
    }

    .page_text {
        float: right;
        line-height: 26px;
    }

    }


    .demo-spin-icon-load{
        animation: ani-demo-spin 1s linear infinite;
    }
    @keyframes ani-demo-spin {
        from { transform: rotate(0deg);}
        50%  { transform: rotate(180deg);}
        to   { transform: rotate(360deg);}
    }
    .demo-spin-col{
        height: 90px;
        position: relative;
    }
</style>
